package com.zx.domain;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.zx.service.wxService;
import com.zx.wx.parameter;
import com.zx.wx.wxInterface.Base;

/**
 * @author：朱笑    
 * @note：微信基础参数接口
 * @date：2016年7月17日 
 */
@Controller
public class baseImp implements Base{
	@Autowired
	wxService wxservice;
	@Override
	public Map<String,Object> getRamAccess_token(String appID,String appsecret) {
		Map<String,Object> result=new HashMap<>();
		if((parameter.access_token!=null&&parameter.access_token.size()>0)&&(parameter.access_token_update_time!=null&&parameter.access_token_update_time.size()>0)){
			result.put("access_token",parameter.access_token.get(appID+"_"+appsecret));
			result.put("access_token_update_time",parameter.access_token_update_time.get(appID+"_"+appsecret));
		}
		return result;
	}
	//access_token_update_time为毫秒
	@Override
	public void setRamAccess_token(String access_token,String access_token_update_time,String appID,String appsecret) {
		parameter.access_token.put(appID+"_"+appsecret,access_token);
		parameter.access_token_update_time.put(appID+"_"+appsecret,access_token_update_time);
	}
	@Override
	public Map<String, Object> getDBAccess_token(String appID, String appsecret) {
		Map<String,Object> resultMap=wxservice.getAccess_token(appID, appsecret);
		return resultMap;
	}
	@Override
	public void setDBAccess_token(String access_token, String appID, String appsecret) {
		wxservice.setAccess_token(access_token, appID, appsecret);
	}
	@Override
	public void updateDBAccess_token(String access_token, String appID, String appsecret) {
		wxservice.updateAccess_token(access_token, appID, appsecret);
	}
	
	
	@Override
	public Map<String, Object> getRamApi_ticket(String appID, String appsecret) {
		Map<String,Object> result=new HashMap<>();
		if((parameter.api_ticket!=null&&parameter.api_ticket.size()>0)&&(parameter.api_ticket_update_time!=null&&parameter.api_ticket_update_time.size()>0)){
			result.put("api_ticket",parameter.api_ticket.get(appID+"_"+appsecret));
			result.put("api_ticket_update_time",parameter.api_ticket_update_time.get(appID+"_"+appsecret));
		}
		return result;
	}
	
	@Override
	public void setRamApi_ticket(String api_ticket, String api_ticket_update_time, String appID, String appsecret) {
		parameter.api_ticket.put(appID+"_"+appsecret,api_ticket);
		parameter.api_ticket_update_time.put(appID+"_"+appsecret,api_ticket_update_time);
	}
	@Override
	public Map<String, Object> getDBApi_ticket(String appID, String appsecret) {
		return wxservice.getApi_ticket(appID, appsecret);
	}
	@Override
	public void setDBApi_ticket(String api_ticket, String appID, String appsecret) {
		wxservice.setApi_ticket(api_ticket, appID, appsecret);
	}
	@Override
	public void updateDBApi_ticket(String api_ticket, String appID, String appsecret) {
		wxservice.updateApi_ticket(api_ticket, appID, appsecret);
	}
	
	
	
}
